from django.db import models

gender_status = (
    (0,"女"),
    (1,"男")
)

class StoreUser(models.Model):
    username = models.CharField(max_length=32,verbose_name="用户名")
    password = models.CharField(max_length=32,verbose_name="密码")
    nick_name = models.CharField(max_length=32,verbose_name="昵称")
    age = models.IntegerField(verbose_name="年龄")
    gender = models.IntegerField(choices=gender_status,default=1,verbose_name="性别（1-男，0-女）")
    email = models.EmailField(verbose_name="邮箱",null=True,blank=True)
    address = models.TextField(verbose_name="地址",null=True,blank=True)
    create_time = models.DateField(verbose_name="创建时间",auto_now=True)
    # img = models.ImageField(upload_to="img")
    class Meta:
        """修改生成的表名"""
        db_table = "storeuser"


class Store(models.Model):
    store_name = models.CharField(max_length=32,verbose_name="店铺名称")
    store_desc = models.TextField(verbose_name="店铺描述")
    store_address = models.TextField(verbose_name="店铺地址")
    store_user = models.OneToOneField(to="StoreUser",on_delete=models.CASCADE)
    class Meta:
        db_table = "store"

class GoodType(models.Model):
    """商品类型"""
    t_name = models.CharField(max_length=32,verbose_name="类型名")
    t_desc = models.TextField(verbose_name="类型描述")
    goodstype_store = models.ManyToManyField(to="Store")
    class Meta:
        db_table = "good_type"

class Goods(models.Model):
    """商品"""
    goods_name = models.CharField(max_length=32,verbose_name="商品名")
    goods_num = models.IntegerField(verbose_name="商品数量")
    goods_price = models.FloatField(verbose_name="商品价格")
    goods_type = models.ForeignKey(to="GoodType",on_delete=models.CASCADE)
    class Meta:
        db_table = "goods"

#出版社
class Publisher(models.Model):
    name = models.CharField(max_length=32)
    city = models.CharField(max_length=32)

#书籍
class Book(models.Model):
    title = models.CharField(max_length=32)
    publish_date = models.DateField(auto_now_add=True)
    price = models.DecimalField(max_digits=5,decimal_places=2)
    memo = models.TextField(null=True)
    #创建外键,关联Publisher
    Publisher = models.ForeignKey(to='Publisher',on_delete=models.CASCADE)

#作者
class Author(models.Model):
    name = models.CharField(max_length =32)
    age = models.IntegerField()
    phone = models.CharField(max_length=11)
    #创建多对多关联
    books = models.ManyToManyField(to='Book')


















